import request from "@/utils/request";

const STOCKTRANSFER_BASE_URL = "/api/v1/stockTransfers";

const StockTransferAPI = {
  /** 获取银证转账分页数据 */
  getPage(queryParams?: StockTransferPageQuery) {
    return request<any, PageResult<StockTransferPageVO[]>>({
      url: `${STOCKTRANSFER_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },

  /** 获取银证转账统计数据 */
  getStatistic(statisticParams?: StockTransferStatisticQuery) {
    return request<any, StockTransferStatistic>({
      url: `${STOCKTRANSFER_BASE_URL}/statistic`,
      method: "get",
      params: statisticParams,
    });
  },

  /**
   * 获取银证转账表单数据
   *
   * @param id 银证转账ID
   * @returns 银证转账表单数据
   */
  getFormData(id: number) {
    return request<any, StockTransferForm>({
      url: `${STOCKTRANSFER_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /** 添加银证转账*/
  add(data: StockTransferForm) {
    return request({
      url: `${STOCKTRANSFER_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新银证转账
   *
   * @param id 银证转账ID
   * @param data 银证转账表单数据
   */
  update(id: number, data: StockTransferForm) {
    return request({
      url: `${STOCKTRANSFER_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除银证转账，多个以英文逗号(,)分割
   *
   * @param ids 银证转账ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${STOCKTRANSFER_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default StockTransferAPI;

/** 银证转账分页查询参数 */
export interface StockTransferPageQuery extends PageQuery {
  /** 转账日期 */
  tranDate?: [string, string];
}

/** 银证转账统计查询参数 */
export interface StockTransferStatisticQuery {
  /** 转账日期 */
  tranDate?: [string, string];
}

/** 银证转账统计查询结果 */
export interface StockTransferStatistic {
  /** 开始日期 */
  startDate?: string;
  /** 结束日期 */
  endDate?: string;
  /** 总金额 */
  totalAmount?: number;
  /** 月汇总 */
  monthItemVOList?: StockTransferMonthRollup[];
}

/** 银证转账统计查询结果月汇总 */
export interface StockTransferMonthRollup {
  /** 月份 */
  month?: string;
  /** 金额 */
  amount?: number;
}

/** 银证转账表单对象 */
export interface StockTransferForm {
  /** id */
  id?: number;
  /** 转账日期 */
  tranDate?: Date | string;
  /** 转账金额 */
  amount?: number;
}

/** 银证转账分页对象 */
export interface StockTransferPageVO {
  /** 转账日期 */
  tranDate?: Date;
  /** 转账金额 */
  amount?: number;
}
